package com.panda.service.impl;

import lombok.extern.slf4j.Slf4j;
import com.panda.mapper.ProductInfoMapper;
import com.panda.model.ProductInfo;
import com.panda.param.ProductInfoQueryParam;
import com.panda.service.ProductInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
@Slf4j
public class ProductInfoServiceImpl implements ProductInfoService {

    @Autowired
    private ProductInfoMapper productInfoMapper;

    @Override
    public List<ProductInfo> list(ProductInfoQueryParam queryParam) {
        log.info("查询产品列表入参: {}", queryParam.toString());
        Example example = new Example(ProductInfo.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.hasText(queryParam.getId())) {
            criteria.andEqualTo("id", queryParam.getId());
        }
        if (StringUtils.hasText(queryParam.getUserId())) {
            criteria.andEqualTo("userId", queryParam.getUserId());
        }
        return productInfoMapper.selectByExample(example);
    }
}
